package com.nowcoder.community;

import com.nowcoder.community.util.MailClient;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

/**
 * @author 夏智力
 * @FileName MailText
 * @date 2021/5/31 18:19
 * @Software: IntelliJ IDEA
 */
@SpringBootTest
@ContextConfiguration(classes = CommunityApplication.class)
public class MailText {

    @Autowired
    private MailClient client;

    @Autowired
    private TemplateEngine templateEngine;

    @Test
    public void testMail() {
        client.sendMail("zdan2898570338@foxmail.com", "测试邮箱发送", "创子哥牛子小小的");
    }

    @Test
    public void testHtmlMail() {
        Context context = new Context();
        context.setVariable("username", "夏智力");

        String content = templateEngine.process("/mail/demo", context);
        System.out.println(content);
        client.sendMail("zdan2898570338@foxmail.com", "测试邮箱发送",content);
    }
}
